<%@page import="java.math.BigDecimal"%>
<%@page import="com.opensymphony.xwork2.ActionContext"%>
<%@page import="com.milk_shop.model.Package" %>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<% 
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%List<Package> packages=(List<Package>)ActionContext.getContext().get("packages");%>
<base href="<%=basePath %>"/>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>用户点单界面</title>
  <script src="js/vue.js"></script>
  <script src="js/vue-router.js"></script>
  <script src="js/httpVueLoader.js"></script>
  <link rel="stylesheet" href="https://unpkg.com/element-ui@2.14.1/lib/theme-chalk/index.css">
  <script src="https://unpkg.com/element-ui@2.14.1/lib/index.js"></script>
  <style>
    .button {
      padding: 0;
      float: right;
    }

    .product-info {
      float: left;
      text-align: left;
      margin: 0 20px 10px 20px;
    }

    .image {
      width: 180px;
      display: block;
    }

    .container {
      width: 100%;
      margin: 0 50px 0 0;
    }

    .food-card {
      text-align: center;
      width: 400px;
    }

    .food-img {
      float: left;
    }
  </style>
</head>
<body>
<div id="app">
    <el-container style="height: 650px;">
      <sider-component></sider-component>
      <div class="container">
        <el-container>
          <el-main>
            <el-row v-for="(i,row) in Math.ceil(this.items.length / 3)" :key="i" style="margin-bottom: 15px">
              <el-col :span="6" v-for="(o, col) in (i==Math.ceil(items.length / 3)?<%=packages.size() % 3==0?3:packages.size()%3 %>:3)" :key="o" :offset="col > 0 ? 3 : 0">
                <el-card class="food-card" shadow="hover">
                  <div class="food-img">
                    <div  @click="cardClick(items[row*3+col].id)"><img :src="items[row*3+col].cover" class="image"></div>
                    <div style="text-align: left">
                      <p>套餐内容：</p>
                      <p>饮品：{{items[row*3+col].fName1}}</p>
                      <p>甜品：{{items[row*3+col].fName2}}</p>
                      <div style="float: right; margin-right: 0; padding: 0;">
                        <el-button type="danger" icon="el-icon-plus" @click="addFood(items[row*3+col].id)" circle></el-button>
                      </div>
                    </div>
                  </div>
                  <div class="product-info">
                    <p>套餐名：{{items[row*3+col].name}}</p>
                    <p>套餐价：{{items[row*3+col].price}}元</p>
                  </div>

                </el-card>
              </el-col>
            </el-row>
          </el-main>
        </el-container>
      </div>
    </el-container>
  </div>
  <script>
    Vue.use(httpVueLoader);

    new Vue({
      el: "#app",
      components: {
        'sider-component': 'url:component/SiderBar.vue',
      },
      data: {
    	  items:[
    		  <%for(Package package1:packages){%>
    		  {
    			 id:'<%=package1.getId()%>', 
    			 cover:'<%=package1.getCover()%>',
    			 name:'<%=package1.getName()%>',
    			 price:'<%=package1.getPrice()%>',
    			 fName1:'<%=package1.getFoods().get(0).getName()%>',
    			 fName2:'<%=package1.getFoods().get(1).getName()%>',
    		  },
    		  <%}%>
    	  ]
      },
        methods: {
        cardClick(id){
        	window.location.href="order/getPackageDetail?PackageId="+id;
        },
    	addFood(id) {
    		window.location.href="order/addPackage?PackageId="+id;
          	alert("加入购物车成功");
        },
      },
    })
  </script>
</body>
</html>